<template>
  <div class="goods-item" @click="itemclick">
    <img v-lazy="showimage" alt="" />
    <div class="goods-info">
      <p>{{ goodsitem.title }}</p>
      <span class="price">{{ goodsitem.price }}</span>
      <span class="cfav">{{ goodsitem.cfav }}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: "goodsitem",
  props: {
    goodsitem: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  computed: {
    showimage() {
      return this.goodsitem.image || this.goodsitem.show.img;
    },
  },
  methods: {
    itemclick() {
      this.$router.push("/detail/" + this.goodsitem.iid);
    },
  },
};
</script>

<style>
.goods-item {
  position: relative;
  width: 48%;
  padding-bottom: 40px;
}
.goods-item img {
  width: 100%;
  border-radius: 5px;
}
.goods-info {
  font-size: 12px;
  text-align: center;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 5px;
}
.goods-info p {
  overflow: hidden;
  margin-bottom: 5px;
  white-space: nowrap; /* 规定段落中的文本不进行换行 */
  text-overflow: ellipsis; /*显示省略符号来代表被修剪的文本*/
  color: black;
}
.goods-info .price {
  margin-right: 25px;
  color: var(--color-high-text);
}
.goods-info .cfav {
  position: relative;
  color: black;
}
.goods-info .cfav::before {
  content: "";
  /*绝对定位开启后行内会变成块元素*/
  position: absolute;
  left: -15px;
  top: -1px;
  background-image: url("~assets/img/common/collect.svg");
  background-size: 14px;
  width: 14px;
  height: 14px;
}
</style>